﻿--#include "data\config\ActorEvent\UserDepotCfg.lua" once

--购买随身仓库格子
function OnEventBuyUserDepotGrid(sysarg, args)
	local pageGridCount = args[1] 	-- 每页格子数
	local gridId = args[2]	-- 格子ID,从1开始
	
	local curGridCount = Actor.getUserDepotGridCount(sysarg)
	if curGridCount >= gridId then
		return -- 已经开启了
	end
	
	local totalYb = 0
	for i=curGridCount+1,gridId do
		local needYb = UserDepotCfg.ActivateGridsNeedYb[i-pageGridCount]
		if needYb == nil then return end
		
		totalYb = totalYb + needYb
	end


	local costMoney = {{type = qatBindYb, id = 0 , count = totalYb,},}

	if not CheckConsumeCond( sysarg, costMoney, 1 ) then
		return
	end

	if not DoConsumeCond( sysarg, costMoney, 1, LogIds.BuyUserDepotGrid, "buy_depotgrid" ) then
		return
	end
	
	Actor.setUserDepotGridCount(sysarg, gridId)
end


EventCallDispatcher.registerEventCall(BaseTypes.ActorEventId.aeBuyUserDepotGrid, OnEventBuyUserDepotGrid) --购买随身仓库格子
